package com.gdpu.service.impl;

import com.gdpu.config.RedisConfig;
import com.gdpu.dao.PortalPmsCategoryDao;
import com.gdpu.mapper.PmsCategoryMapper;
import com.gdpu.model.PmsCategory;
import com.gdpu.model.PmsCategoryExample;
import com.gdpu.service.PortalPmsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:weiming
 * @Date:2021/6/10
 */
@Service
public class PortalPmsCategoryServiceImpl implements PortalPmsCategoryService {
    @Autowired
    private PmsCategoryMapper pmsCategoryMapper;
    @Autowired
    private PortalPmsCategoryDao portalCategoryDao;

    @Override
    @Cacheable(value = RedisConfig.REDIS_KEY_DATABASE, key = "'oms:category:all'", unless = "#result==null")
    public List<PmsCategory> getAllParentCategory() {
        PmsCategoryExample example = new PmsCategoryExample();
        example.createCriteria().andIsDeletedEqualTo(0).andParentIdIsNull();
        List<PmsCategory> pmsCategories = pmsCategoryMapper.selectByExample(example);
        return pmsCategories;
    }


    @Override
    @Cacheable(value = RedisConfig.REDIS_KEY_DATABASE,key = "'oms:category:'+#categoryId",unless = "#result==null")
    public List<PmsCategory> getChildByFirstCategoryId(Integer categoryId) {
        List<PmsCategory> list = portalCategoryDao.getChildByFirstCategoryId(categoryId);
        return list;
    }
}
